package com.lc.luzhengtang.conn;

import android.util.Log;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/14.
 */

@HttpInlet(Conn.INDEX_SHOPLIST)
public class ConnIndexShopList extends BaseAsyPost<ConnIndexShopList.Info> {
    public String member_id;
    public int page;
    public String goodstype_id;

    public ConnIndexShopList(String member_id, int page, String goodstype_id, AsyCallBack<ConnIndexShopList.Info> asyCallBack) {
        super(asyCallBack);
        this.member_id = member_id;
        this.page = page;
        this.goodstype_id = goodstype_id;
    }


    @Override
    protected ConnIndexShopList.Info parser(JSONObject object) throws Exception {
        Log.d(object.toString(), "33333333333333333");
       /* Gson gson = new Gson();
        ShopListBean shopListBean = new ShopListBean();

        gson.fromJson(object.toString(), ShopListBean.class);
        return shopListBean;
*/
        Info info = null;
        if (object.optInt("code") == 200) {
            info = new Info();
            Info.Page page = new Info.Page();
            JSONObject jsonObject = object.optJSONObject("data");
            page.current_page = jsonObject.optInt("current_page");
            page.per_page = jsonObject.optInt("per_page");
            page.total = jsonObject.optInt("total");

            info.page = page;

            JSONArray array = jsonObject.optJSONArray("data");
            List<Info.NewListContent> data = new ArrayList();
            for (int i = 0; i < array.length(); i++) {
                JSONObject object1 = array.optJSONObject(i);
                Info.NewListContent listContent = new Info.NewListContent();
                listContent.id = object1.optInt("id");
                listContent.market_price = object1.optString("market_price");
                listContent.picurl = object1.optString("picurl");
                listContent.sales = object1.optString("sales");
                listContent.title = object1.optString("title");
                listContent.volume = object1.optString("volume");
                data.add(listContent);
            }
            info.data = data;

            return info;

        }

        return null;

    }


    public static class Info {

        public List<NewListContent> data;

        public Page page;


        public static class Page {
            public int total;
            public int per_page;
            public int current_page;
        }

        public static class NewListContent {
            public int id;
            public String picurl;
            public String title;
            public String market_price;
            public String volume;
            public String sales;

        }


    }

}
